package com.briup.corejava.day20;

import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 将基本数据类型和字符串写入到文件
 */
public class Test1_dw {
    public static void main(String[] args) {
        // 选择流：输出流、数据流和文件流
        DataOutputStream dos = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("src/com/briup/corejava/day20/file/data.txt");
            dos = new DataOutputStream(fos);
            // 写出数据
            dos.writeInt(20);
            dos.writeLong(30L);
            dos.writeDouble(20.01);
            dos.writeFloat(34.76F);
            dos.writeBoolean(true);
            dos.writeChar('a');
            dos.writeUTF("今天星期一");
            System.out.println("数据写入完毕。。");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(dos!=null) {
                try {
                    dos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
